<%--
  Created by IntelliJ IDEA.
  User: HUAWEI
  Date: 2023/9/30
  Time: 9:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="domain.NewsType" %>
<%@ page import="java.util.List" %>
<%@ page import="service.NewsTypeService" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    // 得到已经给对象属性赋好值的对象集合
    List<NewsType> newsTypeList= NewsTypeService.getNewsTypeServices();
    // 将集合存到域对象中
    pageContext.setAttribute("newsTypeList",newsTypeList);
%>

<div class=".container-fluid" style="height: 110px">
    <div class="float-left"></div>

    <%--导航栏图标--%>
    <div class="header-img"><img src="images/log.jpg" alt="加载中！"/></div>

    <%--导航栏--%>
    <div class="p-3 mb-2 bg-dark text-white">
        <div class="container">
            <div class="row">
                <div class="col-auto mr-auto"></div>
                <%--获取域对象中的类别集合，用forEach遍历集合--%>
                <c:forEach var="newsType" items="${newsTypeList}">
                    <%--点击相应的字段传入对应的导航栏的id并作为参数--%>
                    <div class="col">
                        <a href="${pageContext.request.contextPath}/news?reqNewsTypeId=${newsType.newsTypeId}">
                                ${newsType.newsTypeName}
                        </a>
                    </div>
                </c:forEach>

                <div class="col">
                    <%--下拉菜单栏--%>
                    <div class="nav-item dropdown" style="position: absolute;top:-8px;left: -3px">
                        <%--使用el表达式判断域对象中是否为空，若为空显示‘未登录’--%>
                        ${not empty User? "<a class=\"nav-link dropdown-toggle\" href=\"#\" role=\"button\" data-toggle=\"dropdown\" aria-expanded=\"false\">".concat(User.userName).concat("，你好</a>")
                                :"<a class=\"nav-link dropdown-toggle\" href=\"#\" role=\"button\" data-toggle=\"dropdown\" aria-expanded=\"false\">未登录</a>"
                                }

                            <%--下拉菜单栏内容--%>
                        <ul class="dropdown-menu">
                            <%--使用el表达式判断域对象中是否为空，若为空显示‘登录、注册’--%>
                            ${not empty User? "<li><a class=\"dropdown-item\" href=\"#\">用户信息</a></li><li><a class=\"dropdown-item\" href=\"LogOff\">退出登录</a></li>"
                                :"<li><a class=\"dropdown-item\" href=".concat(pageContext.request.contextPath).concat("/login>登 录</a>").concat("</li><li><a class=\"dropdown-item\" href=").concat(pageContext.request.contextPath).concat("/register>注 册</a></li>")
                                }
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <%--搜索--%>
    <div class="container">
        <div class="row">
            <div class="col-md-3 offset-md-3"></div>
            <div class="col-md-3 offset-md-3">
            <form method="get" action="searches">
                <div class="input-group mb-3">
                        <input type="text" name="search" class="form-control" <%--placeholder="输入搜索内容..." aria-label="输入搜索内容..."--%> <%--aria-describedby="button-addon2"--%>>
                        <div class="input-group-append">
                            <button class="btn btn-dark btn-xs" type="submit" <%--id="button-addon2"--%>>搜索</button>
                        </div>
                </div>
            </form>
            </div>
        </div>
    </div>
</div>


